﻿using System;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;

namespace PmSadis.CsExtantions
{
    /// <summary>
    /// Расширяющие методы перечислений
    /// </summary>
    public static  class EnumExt
    {
        public static string GetDescription(this Enum e)
        {
            var type = e.GetType();
            MemberInfo[] memberInfo = type.GetMember(e.ToString());
            if (memberInfo != null && memberInfo.Length > 0)
            {
                object[] attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attrs != null && attrs.Length > 0)
                    return ((DescriptionAttribute)attrs[0]).Description;
            }
            return e.ToString();
        }
    }
}
